package com.zyh.demo;

import java.io.*;

/**
 * @Author zyh
 * @Date 2024/8/6 10:52
 * @Description 转换流的按照编码的读与写
 */

public class IODemo1 {
    public static final String FILE_PATH="D:\\Code\\IDEA\\idea_projects\\JavaSE-plus\\day10-code\\src\\com\\zyh\\resources\\User.txt";
    public static void main(String[] args) throws IOException {
        FileInputStream fis = new FileInputStream(FILE_PATH);
        FileOutputStream fos=new FileOutputStream(FILE_PATH,true);
        readAndWriter(fis,fos);

    }
    public static void readAndWriter(FileInputStream fis, FileOutputStream fos) throws IOException {
        //读
        InputStreamReader isr = new InputStreamReader(fis, "GBK");
        char[] car=new char[1024];
        int len=-1;
        while ((len=isr.read(car))!=-1){
            System.out.println(car);
        }
        //写
        //创建转换流
        OutputStreamWriter osw = new OutputStreamWriter(fos, "GBK");
        String str="维新派";
        osw.write(str);
        osw.flush();
        osw.close();
        isr.close();
    }
}
